﻿using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace SerilogLearn.ConsoleApp;

internal class TestService(ILogger<TestService> logger) : IHostedService
{
    public Task StartAsync(CancellationToken cancellationToken)
    {
        logger.LogTrace("TestService StartAsync");
        logger.LogDebug("TestService StartAsync");
        logger.LogInformation("TestService StartAsync");
        logger.LogWarning("TestService StartAsync");
        Exception innerException = new NotImplementedException("测试内部异常");
        Exception exception = new NotImplementedException("测试异常", innerException);
        logger.LogError(exception, "TestService StartAsync");
        logger.LogCritical(exception, "TestService StartAsync");
        return Task.CompletedTask;
    }
    public Task StopAsync(CancellationToken cancellationToken)
    {
        logger.LogTrace("TestService StopAsync");
        logger.LogDebug("TestService StopAsync");
        logger.LogInformation("TestService StopAsync");
        logger.LogWarning("TestService StopAsync");
        Exception innerException = new NotImplementedException("测试内部异常");
        Exception exception = new NotImplementedException("测试异常", innerException);
        logger.LogError(exception, "TestService StopAsync");
        logger.LogCritical(exception, "TestService StopAsync");
        return Task.CompletedTask;
    }
}